package com.dianneng.show.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.dianneng.show.R;
import com.dianneng.show.adapter.MyFragmentPagerAdapter;
import com.dianneng.show.base.BaseFragment;
import com.dianneng.show.fragment.CompareFragment;
import com.dianneng.show.fragment.InfoFragment;
import com.dianneng.show.fragment.StateFragment;
import com.dianneng.show.util.DateUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Main2Activity extends AppCompatActivity implements ViewPager.OnPageChangeListener {

    @BindView(R.id.vp_content)
    ViewPager vpContent;

    List<BaseFragment> fragments=new ArrayList<>();
    MyFragmentPagerAdapter fragmentPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ButterKnife.bind(this);

        vpContent.addOnPageChangeListener(this);


        fragments.add(new StateFragment());
        fragments.add(new InfoFragment());
        fragments.add(new CompareFragment());

        fragmentPagerAdapter=new MyFragmentPagerAdapter(getSupportFragmentManager(),fragments);
        vpContent.setAdapter(fragmentPagerAdapter);
        vpContent.setOffscreenPageLimit(3);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DateUtil.clearData();
    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {

    }

    @Override
    public void onPageSelected(int i) {

    }

    @Override
    public void onPageScrollStateChanged(int i) {

    }
}
